package com.kira.scaffoldmvc.DataSource;

import com.kira.scaffoldmvc.Mapper.ds1.DictionaryMapper;
import com.kira.scaffoldmvc.Mapper.ds2.DsTestMapper;
import com.kira.scaffoldmvc.POJO.Dictionary;
import com.kira.scaffoldmvc.POJO.Result;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DataSourceTestServiceImpl implements DataSourceTestService {

    @Resource
    DictionaryMapper dictionaryMapper;

    @Resource
    DsTestMapper dsTestMapper;

    @Transactional(rollbackFor = Exception.class ,transactionManager = "ds1TransactionManager")
    @Override
    public Result testDataSource1() {
        List<Dictionary> dictionaries = dictionaryMapper.selectAll();
        dictionaryMapper.batchInsert(dictionaries);
        return Result.success("数据插入成功");
    }

    @Transactional(rollbackFor = Exception.class ,transactionManager = "ds1TransactionManager")
    @Override
    public Result testDataSource2() {
        List<DsTest> dsTests = dsTestMapper.selectAll();
        dsTestMapper.batchInsert(dsTests);
        return Result.success("数据插入成功");
    }


    @Override
    public Result testMutipleDataSource() {
        return null;
    }
}
